package test;

import org.nutz.dao.impl.NutDao;
import org.nutz.ioc.IocLoader;
import org.nutz.ioc.impl.NutIoc;
import org.nutz.ioc.loader.json.JsonLoader;

import javax.sql.DataSource;


/**
 * Created by Administrator on 2017/5/17.
 */
public class servicetest {
    public static void main(String[] args) throws Exception {
        // Object[] objs = smsClient.invoke("insertdw", new Object[] { "12", "海门宝钢" });

        IocLoader loader = new JsonLoader("ioc/dao.js");
        NutDao dao = (new NutIoc(loader)).get(NutDao.class, "dao");
        DataSource dataSource = (new NutIoc(loader)).get(DataSource.class, "dataSource");

/*
        List<Record> list = dao.query("dt_dep", Cnd.NEW());
        for (Record r : list) {
            System.out.println(r.get("dep_serial"));
           Object[] objs = smsClient.invoke("upbm", new Object[]{Integer.parseInt(r.get("dep_serial").toString()), r.get("dep_name"), r.get("dep_name"), "3"});
            System.out.println(objs[0]);
        }*/


       /* List<Record> list = dao.query("view_nt_zhye", Cnd.NEW());

        Object[] para = new Object[13];
        for (Record r : list) {
            para[0] = r.get("user_lname"); //xm s:string 姓名
            para[1] = r.get("user_no");//bh s:string   编号
            para[2] = r.get("user_card");//mac s:string  物理卡号
            para[3] = r.get("user_id");//sfz s:string  身份证号
            para[4] = r.get("user_telephone");//phone s:string 电话号码
            para[5] = "员工";//sfmc s:string 身份名称
            para[6] = r.get("user_serial").toString();//dz s:string 逻辑地址
            para[7] = "1";//bzint s:string  办卡次数
            para[8] = "1";//bz s:string       标志
            para[9] = r.get("user_dep").toString();//bmid s:string 部门ID
            para[10] = 3;//sfid s:int  身份ID
            para[11] = Double.parseDouble(r.get("syje").toString());//syje s:double  账户余额
            para[12] = "10";//dw s:string  单位代码

            Object[] objs = smsClient.invoke("upuser", para);
            System.out.println(objs[0]);
        }
*/
       /*Object[] objs = smsClient.invoke("insertdw", new Object[] { "1", "测试" });
        System.out.println(objs);*/


       /* Object[] objs = smsClient.invoke("selectgs", new Object[] { "3" });
        System.out.println(objs);*/


       //消费明细
     /* List<Record> list = dao.query("view_nt_xfmx", Cnd.NEW());
        Object[] para = new Object[14];
        for (Record r : list) {

            para[0] = r.get("user_no");  // <bh>string</bh> 编号
            para[1] = r.get("user_lname");  //   <xm>string</xm> 姓名
            para[2] = r.get("user_card"); //  <kh>string</kh> 物理卡号
            para[3] = r.get("场所名称");  //<xfdd>string</xfdd> 消费地点
            para[4] = r.get("交易日期"); // <xfrq>string</xfrq> 消费日期
            para[5] = r.get("time"); // <xfsj>string</xfsj> 消费时间
            para[6] = r.get("xh");  //   <dwxh>int</dwxh> 客户端流水号
            para[7] = r.get("xh"); //  <record>int</record> 设备记录号
            para[8] = r.get("xz");  //  <xz>int</xz> 性质
            para[9] = Integer.parseInt(r.get("user_serial").toString()); //  <dz>int</dz> 逻辑地址	对应user_serial
            para[10] = Integer.parseInt(r.get("设备编号").toString()); //       <zdjh>int</zdjh> 终端机号
            para[11] = Double.parseDouble( r.get("消费明细").toString()); //  <xfje>double</xfje> 交易金额
            para[12] = Double.parseDouble(r.get("交易后金额").toString()) ; // <ssyje>double</ssyje> 交易后余额
            para[13] = "3";  //   <dw>string</dw> 单位代码
          //  Object[] objs = smsClient.invoke("insertxfjl", para);
            //System.out.println(objs[0]);
        }*/

       /* //考勤
        List<Record> list = dao.query("view_kt_jl", Cnd.NEW());
        Object[] para = new Object[5];

        for (Record r : list) {

            para[0] = "3";  //   <dw>string</dw> 单位代码
            para[1] = r.get("刷卡时间").toString();  //  <sj>dateTime</sj> 刷卡时间
            para[2] = Long.parseLong(r.get("user_serial").toString()); //   <user_serial>long</user_serial> 人员序号
            para[3] = r.get("设备名称");  // <dev_name>string</dev_name> 设备名称
            para[4] = 0; // <lx>int</lx> 考勤类型
            Object[] objs = smsClient.invoke("insertkq", para);
            System.out.println(objs[0]);
        }*/


        //获取挂失信息

      /*  try {
            String id = "";
            String user_serial = "";
            String kh = "";
            Object[] objs = smsClient.invoke("selectgs", new Object[]{"3"});
            System.out.println(objs[0]);

            PreparedStatement pstmt = dataSource.getConnection().prepareStatement("{call ClientPro_Card_loss(?,?,'',1,'127.0.0.1','admin','')}");
            if (!objs[0].equals("20000")) {
                Document doc = XmlUtil.parseXml(objs[0].toString());
                List<Element> list = XmlUtil.getElements(doc.getDocumentElement(), "Table1");
                for (int i = 0; i < list.size(); i++) {

                    try {


                        id = XmlUtil.elementText(list.get(i), "id");
                        user_serial = XmlUtil.elementText(list.get(i), "user_serial");
                        kh = XmlUtil.elementText(list.get(i), "kh");

                        pstmt.setInt(1, Integer.parseInt(user_serial));
                        pstmt.setString(2, kh);
                        pstmt.execute();


                        Object[] objs1 = smsClient.invoke("updategs", new Object[]{id});
                        System.out.println(objs1[0]);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
            }


        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            smsClient.destroy();

        }*/

   /*     PreparedStatement pstmt = dataSource.getConnection().prepareStatement("{call ClientPro_Card_loss(?,?,'',1,'127.0.0.1','admin','')}");
        pstmt.setInt(1, 20000006);
        pstmt.setString(2, "2490F7DC");
        pstmt.execute();*/


       /* Sql sql = Sqls.queryRecord("select top 1000 * from view_nt_mj where not exists ( select 1 from ty_mj where id = xh)");
        dao.execute(sql);
        List<Record> list = sql.getList(Record.class);

        Object[] para = new Object[4];

        for (Record r : list) {

            para[0] = "10";  //   <dw>string</dw> 单位代码
            para[1] = r.get("jl_sj").toString();  //  <sj>dateTime</sj> 刷卡时间
            if (null != r.get("user_serial") && StringUtils.isNotEmpty(r.get("user_serial").toString())) {
                para[2] = Long.parseLong(r.get("user_serial").toString()); //   <user_serial>long</user_serial> 人员序号
            } else {
                para[2] = 0L;
            }

            para[3] = r.get("mc");  // <dev_name>string</dev_name> 设备名称
            Object[] objs = smsClient.invoke("insertmj", para);
            System.out.println(objs[0]);
            if (objs[0].equals(10000)) {
                dao.insert(new MJ(Integer.parseInt(r.get("xh").toString())));
            }


        }*/

    }
}
